Skip to content

CLI v2: OAuth, JSON output, and automation-first overhaul#47

Open
nicped wants to merge 120 commits into
mainfrom
v2
Open

CLI v2: OAuth, JSON output, and automation-first overhaul#47
nicped wants to merge 120 commits into
mainfrom
v2

Conversation

@nicped
Copy link
Copy Markdown
Member

@nicped nicped commented Apr 13, 2026

Summary

  • OAuth client_credentials authentication — new --oauth login flow, --auth flag to override auth mode, env-var-based client credentials (--clientIdEnv/--clientSecretEnv)
  • Structured JSON output--output json across all commands with consistent response envelope (ok, status, data, errors, meta), replacing the deprecated --json flag
  • File operations--delete, --copy, --move support with --asFile/--asDirectory overrides and interactive confirmation for destructive actions
  • Code qualityoutput.finish() via finally blocks, extracted isFilePath helper, encapsulated meta access in output objects, verbose logging for archive cleanup errors, fixed missing output parameter threading through setupEnv/interactiveEnv/interactiveOAuthLogin
  • Documentation — full v2 documentation article, changelog, updated README

QA test scripts

To run the unit tests:

npm test

For QA to run the test smoke harness against a real solution:

export DW_BASE_URL=https://your-solution.example.com
export DW_CLIENT_ID=your-client-id
export DW_CLIENT_SECRET=your-client-secret
npm run qa:smoke

Full instructions (profile format, CI usage, --mode flag, etc.) are in qa/README.md.
https://github.com/dynamicweb/CLI/blob/7ce694f8464dd53c659f26d1950d6fc947b8aebd/qa/README.md

Test plan

  • Run dw with no args — verify environment status display, including when env is missing
  • Run dw login --oauth — verify interactive OAuth setup stores config correctly
  • Run dw query <name> --output json — verify clean JSON output with no console noise
  • Run dw files --delete <path> — verify confirmation prompt and correct API call
  • Run dw files --copy <src> --output json — verify JSON envelope
  • Run dw files --export <path> -v — verify verbose log shows correct operation context
  • Verify --output json and --interactive conflict on the query command
  • Verify deprecated --json flag on files command emits warning and still works

frederik5480 and others added 30 commits August 19, 2022 15:00
…m one by one without the user having to specify them
Suggestion to code highlight command parameters
…ven, so given commands will have to follow the proper command structure instead of only supplying a model
Changing where we send form data to now send the new structure
Reflects page delete example properly, fixes #10
Adding proper content-type header for database command
Enable raw flag functionality for files
Adding short explanation of what the CLI is and can be used for in simpler terms.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a v2/beta overhaul of the DynamicWeb CLI focused on automation-first usage: OAuth client-credentials authentication, consistent --output json envelopes across API-driven commands, expanded file operations (delete/copy/move), and updated documentation/changelog to reflect the new behaviors.

Changes:

  • Add OAuth client-credentials support (--auth oauth, dw login --oauth, env-var based client ID/secret) and surface auth type in the base dw command.
  • Add structured JSON output (--output json, deprecated --json) to env, login, files, query, and command.
  • Expand dw files with destructive/mutating operations (--delete, --empty, --copy, --move) and update docs/README/changelog for v2.

Reviewed changes

Copilot reviewed 4 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
README.md Rewrites README for v2 beta: OAuth, JSON output, files workflows, CI/CD guidance.
package.json Bumps version to 2.0.0-beta.0.
package-lock.json Updates lockfile version metadata to 2.0.0-beta.0.
cliv2-documentation.md Adds full v2 documentation article covering auth, JSON envelopes, command refs.
CHANGELOG.md Adds v2 beta changelog entries for breaking changes/features/improvements.
bin/index.js Adds global OAuth flags and improves base command display (incl. auth type).
bin/commands/env.js Adds --output json support and restructures env command output/error handling.
bin/commands/login.js Adds OAuth login/config flow and JSON envelope support.
bin/commands/query.js Adds --output json, structured output envelope, and improved error propagation.
bin/commands/command.js Adds --output json and structured output envelope.
bin/commands/files.js Adds JSON output, deprecated flag aliases, and new delete/copy/move operations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread CHANGELOG.md
nicped added 11 commits April 13, 2026 22:58
…de, improve error handling

- Login: block interactive prompts in JSON mode; add non-interactive OAuth
  login path; always apply --host override on existing environments
- Files: skip full-export confirmation in JSON mode
- Command: throw error for unimplemented --list instead of returning string
- Login: extract shared OAuth finalization into finalizeOAuthLogin helper
- Install: add JSON output example to README for documentation consistency
- Docs: include install in --output json command lists
Patch release fixing TypeError in uploadFiles when called from install command without a structured output object.
…or testability

- Export parseHostInput, getQueryParams, buildInteractiveQueryParams,
  buildQueryParamsFromArgv, extractQueryPropertyPrompts, getFieldNameFromPropertyPrompt,
  parseCookies, shouldUseOAuth, resolveOAuthConfig, prepareDownloadCommandData,
  isFilePath, wildcardToRegExp, getFilesOperation from their respective modules
- Add setConfigForTests() to config.js and guard getConfig() against null return
- Inject deps (interactiveEnvFn, getPropertiesFn, promptFn) via optional deps param
  in setupEnv and getQueryParams for easier unit testing
- Add test/ suite covering command, env, files, login, query, and utility helpers
- Add qa/ smoke harness (run-smoke.mjs) with fixtures, profile.example.json, and README
  covering saved-env and ephemeral CI flows against a real DynamicWeb solution
- Wire npm run test (node --test) and npm run qa:smoke scripts in package.json
- Bump version to 2.0.0-beta.1
- Ignore qa/artifacts/ and qa/profile.json in .gitignore
…files; add tests for JSON parsing and formatting functions
@MrBuhl
Copy link
Copy Markdown

MrBuhl commented Apr 22, 2026

Setup: Latest master build of dw10 running locally through IIS:
Can't get "dw login --oauth" to work
image
User exists, is administrator and active
image

Creating an OAuth client in backend and passing info to login like
dw login local --auth --clientIdEnv=f28be14b144f4d138671fd8991adea01 --clientSecretEnv=3bb3d0b2f7e549ca9f3450790c8775163f0b4ff5d4334d6e9f2b848b21bf2cb2045cc82fea7848a6b998a42dea7a13ef
fails with
file:///C:/Users/mbp/AppData/Roaming/npm/node_modules/@dynamicweb/cli/bin/commands/login.js:216
getConfig().env[getConfig().current.env].current.user = argv.user;
^

TypeError: Cannot set properties of undefined (setting 'user')
at changeUser (file:///C:/Users/mbp/AppData/Roaming/npm/node_modules/@dynamicweb/cli/bin/commands/login.js:216:59)
at handleLogin (file:///C:/Users/mbp/AppData/Roaming/npm/node_modules/@dynamicweb/cli/bin/commands/login.js:63:17)
at Object.handler (file:///C:/Users/mbp/AppData/Roaming/npm/node_modules/@dynamicweb/cli/bin/commands/login.js:16:28)
at C:\Users\mbp\AppData\Roaming\npm\node_modules@dynamicweb\cli\node_modules\yargs\build\index.cjs:1:8993
at j (C:\Users\mbp\AppData\Roaming\npm\node_modules@dynamicweb\cli\node_modules\yargs\build\index.cjs:1:4956)
at _.handleValidationAndGetResult (C:\Users\mbp\AppData\Roaming\npm\node_modules@dynamicweb\cli\node_modules\yargs\build\index.cjs:1:8962)
at _.applyMiddlewareAndGetResult (C:\Users\mbp\AppData\Roaming\npm\node_modules@dynamicweb\cli\node_modules\yargs\build\index.cjs:1:9604)
at _.runCommand (C:\Users\mbp\AppData\Roaming\npm\node_modules@dynamicweb\cli\node_modules\yargs\build\index.cjs:1:7231)
at [runYargsParserAndExecuteCommands] (C:\Users\mbp\AppData\Roaming\npm\node_modules@dynamicweb\cli\node_modules\yargs\build\index.cjs:1:58539)
at te.parse (C:\Users\mbp\AppData\Roaming\npm\node_modules@dynamicweb\cli\node_modules\yargs\build\index.cjs:1:40478)

Node.js v22.22.1

Test script example is in bash format. We should probably use powershell for documentation, where it would be:
$env:DW_BASE_URL = "your-url"
$env:DW_CLIENT_ID = "your-client-id"
$env:DW_CLIENT_SECRET = "your-client-secret"
npm run qa:smoke

Anyway running test script (both in powershell or bash through wsl) fails with
Running saved-environment flow...
FAIL saved-env: seed config: saved-env-config exited with code 1. file:///C:/source/CLI/bin/commands/files.js:746
async function parseJsonSafe(res) {
^

SyntaxError: Identifier 'parseJsonSafe' has already been declared
at compileSourceTextModule (node:internal/modules/esm/utils:346:16)
at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:107:18)
at #translate (node:internal/modules/esm/loader:546:20)
at afterLoad (node:internal/modules/esm/loader:596:29)
at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:601:12)
at #createModuleJob (node:internal/modules/esm/loader:624:36)
at #getJobFromResolveResult (node:internal/modules/esm/loader:343:34)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:311:41)

Node.js v22.22.1
QA smoke run failed: saved-env-config exited with code 1. file:///C:/source/CLI/bin/commands/files.js:746
async function parseJsonSafe(res) {

nicped added 5 commits April 22, 2026 16:25
…strap, and QA docs

- Remove duplicate parseJsonSafe declaration in files.js (caused SyntaxError on startup)
- Allow dw login --oauth --host to work from a clean state by deriving env name from hostname
- Guard finalizeOAuthLogin against undefined env entry in config
- Add PowerShell env var instructions to qa/README.md
Introduces `dw folders <folderPath>` for unambiguous directory management:
--create and --rename via DirectorySave, --move via DirectoryMove,
--delete/--copy/--export routed through handleFiles (now exported).
Updates README and cliv2-documentation with full command reference.
@MrBuhl
Copy link
Copy Markdown

MrBuhl commented May 1, 2026

With latest changes the qa smoke suite now runs with env var based login.

Still cant get --oauth flow to do anything and any files commands fail as they trigger a login flow and fail
image

@nicped
Copy link
Copy Markdown
Member Author

nicped commented May 4, 2026

--oauth was only implemented for login command - that would then create the dwc. If running --auth oauth it would work on any command
I have now added so any command supports --oauth directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants